package org.flh.book.shop.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.flh.book.shop.common.response.ProTableResponse;
import org.flh.book.shop.common.response.RestResponse;
import org.flh.book.shop.dao.BookDao;
import org.flh.book.shop.service.BookService;
import org.flh.book.shop.common.response.DataTotalView;
import org.flh.book.shop.entity.Book;
import org.flh.book.shop.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 描述：
 *
 * @author 花好月圆
 * @date 2020/11/19 14:03
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public void addBook(Book book) {
        bookDao.addBook(book);
    }

    @Override
    public ProTableResponse<Book> queryCondition(String name, String author,
        Page page) {
        int total = bookDao.queryTotal(name, author);
        if (total == 0) {
            return ProTableResponse.buildSuccess(new ArrayList<>(), page, 0);
        }
        List<Book> bookList = bookDao.queryCondition(name, author, page);
        return ProTableResponse.buildSuccess(bookList, page, total);
    }

    @Override
    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

    @Override
    public void deleteById(int id) {
        bookDao.deleteById(id);
    }

    @Override
    public void batchDelete(List<Integer> idList) {
        bookDao.batchDelete(idList);
    }
}
